package com.tianzmp.ttq.admin.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * <p>
 * 用户基本数据表
 * </p>
 *
 * @author ttq
 * @since 2022-07-26
 */
@Data
@TableName("ups_user_info")
@ApiModel(value = "UserInfo对象", description = "用户基本数据表")
public class UserInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("主键")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty("用户名")
    private String userName;

    @ApiModelProperty("年龄")
    private Integer age;

    @ApiModelProperty("账号")
    private String account;

    @ApiModelProperty("密码")
    private String password;

    @ApiModelProperty("是否锁住")
    private Integer locked;

    @ApiModelProperty("盐")
    private String salt;

    @ApiModelProperty("创建时间")
    private Timestamp createTime;

    private Timestamp updateTime;


    public static void main(String[] args) {
        UserInfo t = new UserInfo();
        t.setId(1L);
        t.setAccount("test1");
        UserInfo t2 = new UserInfo();
        t2.setId(2L);
        t2.setAccount("test2");
        UserInfo t3 = new UserInfo();
        t3.setId(3L);
        t3.setAccount("test3");
        UserInfo t4 = new UserInfo();
        t4.setId(2L);
        t4.setAccount("test4");
        UserInfo t5 = new UserInfo();
        t5.setId(3L);
        t5.setAccount("test5");

        List<UserInfo> list = new ArrayList<UserInfo>();
        list.add(t);
        list.add(t2);
        list.add(t3);
        list.add(t4);
        list.add(t5);

        list = new ArrayList<>();

        List<UserInfo> collect = list.stream().filter(distinctByKey(UserInfo::getAccount)).collect(Collectors.toList());
        System.out.println(JSONObject.toJSONString(collect));


    }

    private static <T> Predicate<T> distinctByKey(Function<? super T,?> keyExtractor){
        Map<Object,Boolean> map=new ConcurrentHashMap<>();
        return t -> map.putIfAbsent(keyExtractor.apply(t),Boolean.TRUE)==null;
    }


}
